package Operation;

import book.BookList;
import user.NormalUser;

import java.util.Scanner;

public class Del implements IOperation{
    public void work(BookList bookList) {
        System.out.println("删除");
        System.out.println("请输入要删除的书名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int index = -1;
        for (int i = 0; i < bookList.NumberBooksExisted; i++) {
            if(name.equals(bookList.books[i].getName())) {
                index = i;
            }
        }
        if(index == -1) {
            System.out.println("未找到");
            return;
        } else {
            while (index+1 < bookList.NumberBooksExisted) {
                bookList.books[index] = bookList.books[index+1];
                index++;
            }
            bookList.NumberBooksExisted--;
            bookList.books[index] = null;
        }
    }
}
